<?php

use peng\helpers\Html;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="/public/openapi/css/bootstrap-2.3.2.min.css">   
            <script src="/public/openapi/js/jquery-1.8.0.min.js"></script>
            <script src="/public/openapi/js/json2.js"></script>
    </head>
    <body>
        <div class="form-customer form-horizontal" style="margin:20px">
            <div class="control-group">
                <label class="control-label">加密字串</label>
                <div class="controls">
                    <?php echo Html::text('key', NULL, array('class' => 'input-large')) ?>
                    <?php echo Html::button('加密=>', array('class' => 'btn btn-primary', 'onclick' => 'getkey()')) ?> 
                    <?php echo Html::text('encode_key', NULL, array('class' => 'input-xlarge')) ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">接口名称</label>
                <div class="controls">
                    <?php echo Html::select('api', $this->api, NULL, array('onchange' => 'getm()')); ?>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">验证码</label>
                <div class="controls">
                    <?php echo Html::img('/openapi/verifycode', array('onclick' => 'this.src="/openapi/verifycode?r="+Math.random();', 'alt' => '看不清，点击刷新', 'style' => 'cursor:pointer;')); ?>  
                </div>
            </div>
            <div class="control-group">
                <table class="table">
                    <tr>
                        <td style="width:40%"><?php echo Html::textArea('inputText', NULL, array('style' => 'width:100%;height:500px;')); ?></td>
                        <td style="text-align:center;vertical-align:middle"><?php echo Html::button('执行=>', array('class' => 'btn btn-primary', 'onclick' => 'run()')) ?> </td>
                        <td style="width:50%"><?php echo Html::textArea('outResult', NULL, array('style' => 'width:100%;height:500px;')); ?></td>
                    </tr>
                </table>
            </div>
        </div>
        <script>

            function getkey() {
                $.ajax({
                    type: 'POST',
                    url: '/openapi/demo/valikey',
                    data: {key: $('input[name="key"]').val()},
                    dataType: 'json',
                    success: function(msg) {
                        msg.data && $('input[name="encode_key"]').val(msg.data);
                    }
                });
            }

            function getm() {
                $.ajax({
                    type: 'POST',
                    url: '/openapi/demo/func/' + $('select[name="api"]').val(),
                    dataType: 'json',
                    success: function(msg) {
                        msg && $('textarea[name="inputText"]').val(JSON.stringify(msg, null, 4));
                    }
                });
            }

            function run() {
                $.ajax({
                    type: 'POST',
                    url: '/openapi/ajaxrequest/run/' + $('select[name="api"]').val(),
                    contentType: 'application/json',
                    data: $('textarea[name="inputText"]').val(),
                    dataType: 'json',
                    success: function(msg) {
                        msg && $('textarea[name="outResult"]').val(JSON.stringify(msg, null, 4));
                    }
                });
            }

        </script>
    </body>
</html>